<template>
	<view class="content">
		<!-- #ifdef H5 || APP-PLUS -->
		<view class="message-title">
			<commonTitle title="个人资料"></commonTitle>
		</view>
		<!-- #endif -->
		<view class="list-scroll-content">
			<view class="user-info-item" @click="choseImg">
				<view class="item-title">头像</view>
				<view class="item-right">
					<image :src="userInfo.headimg?getImgUrl(userInfo.headimg):'../../../static/common/baseinfo-user'" class="user-avator-small"></image>
					<image src="../../../static/common/question-icon.png" class="question-icon"></image>
				</view>
			</view>
			
			<view class="user-info-item" @tap="openShare">
				<view class="item-title">我的ID/邀请二维码</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">查看</view>
					</view>
				</view>
			</view>
			
			<view class="user-info-item" @tap="setAddress">
				<view class="item-title">收货地址</view>
				<view class="item-right">
					<view class="item-right">
						<image src="../../../static/common/question-icon.png" class="question-icon"></image>
					</view>
				</view>
			</view>
			
			<view class="tips">*信息绑定后不可更改，请务必确保真实性（+100经验）</view>
			
			<view class="user-info-item">
				<view class="item-title">性别设置</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2" v-if="userInfo.sex">
							{{userInfo.sex}}
						</view>
						<view class="user-text2" v-else>
							<picker @change="bindPickerChange" :value="index" :range="array" range-key="name">
								<view class="uni-input">{{ userInfo.sex ? array[index].name : '未绑定'}}</view>
							</picker>
						</view>
					</view>
				</view>
			</view>
			
			
			
			<view class="user-info-item" @tap="openAge">
				<view class="item-title">年龄</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.age ? userInfo.age : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="tips">*信息绑定后不可更改，请务必确保真实性（+250经验）</view>
			
			<view class="user-info-item" @tap="openTaobaoID">
				<view class="item-title">绑定淘宝买号</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.taobaoID ? userInfo.taobaoID : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item" @tap="showCL">
				<view class="item-title">常购类目</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.type ? userInfo.type : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item">
				<view class="item-title">开通花呗</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2" v-if="userInfo.isHuabei==0||userInfo.isHuabei==1">
							{{userInfo.isHuabei == 0 ? "未开通":"已开通"}}
						</view>
						<view class="user-text2" v-else>
							<picker @change="bindPickerChangeHB" :value="HBIndex" :range="HB" range-key="hb">
								<view class="uni-input">{{ userInfo.isHuabei ? HB[HBIndex].hb : '未绑定'}}</view>
							</picker>
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item" @tap="openTaoqiV">
				<view class="item-title">淘气值</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
								{{ userInfo.taoqizhi ? userInfo.taoqizhi : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item">
				<view class="item-title">信誉等级</view>
				<view class="item-right">
					<view class="user-text2" v-if="userInfo.mLevel">
						{{userInfo.mLevel}}
					</view>
					<view class="user-text2" v-else>
						<picker @change="bindPickerChangeLevel" :value="mLevelIndex" :range="mLevel" range-key="leavel">
							<view class="uni-input">{{ userInfo.mLevel ? mLevel[mLevelIndex].leavel : '未绑定'}}</view>
						</picker>
					</view>
				</view>
				
			</view>
			<view class="tips">*方便管理员及时处理您遇到的问题（+150经验）</view>
			
			
			<view class="user-info-item" @tap="openPhone">
				<view class="item-title">手机号</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.phone ? userInfo.phone : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item" @tap="openQQ">
				<view class="item-title">绑定QQ号</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.qq ? userInfo.qq : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-item" @tap="openWX">
				<view class="item-title">绑定微信号</view>
				<view class="item-right">
					<view class="item-right">
						<view class="user-text2">
							{{ userInfo.weixin ? userInfo.weixin : "未绑定" }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 我的ID/邀请二维码 -->
		<uni-popup ref="showInviteID" :type="type">
			<view class="edit-block2 edit-qrcode-block">
				<view class="edit-item2" style="color: #111739;">面对面扫码安装</view>
				<view class="edit-item2 qrcode-block">
					<image src="../../../static/common/invite-qrcode.png" class="inviteqrcode"></image>
				</view>
				<view class="edit-item2 myAlbum">邀请码：{{userInfo.keyId}}</view>
			</view>
			<text class="uni-share-btn" @click="cancel('InviteID')">关闭</text>
			<view style="width: 100%;height: 38upx;"></view>
		</uni-popup>
		<!-- 修改头像 -->
		<!-- <uni-popup ref="showshare" :type="type" @change="change">
			<view class="edit-block2">
				<view class="edit-item2">更换头像</view>
				<view class="edit-item2">拍照</view>
				<view class="edit-item2 myAlbum">我的相册</view>
			</view>
			<text class="uni-share-btn" @click="cancel('share')">关闭</text>
			<view style="width: 100%;height: 38upx;"></view>
		</uni-popup> -->
		<!-- 年龄 -->
		<uni-popup ref="showAge" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写年龄</view>
				<view class="invite-small-title">填写年龄</view>
				<input type="number" focus="true" class="invite-input" v-model="userInfo.age"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('Age')">取消</view>
					<view class="invite-submit" @tap="BindAge">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- 淘宝号 -->
		<uni-popup ref="showTaobaoID" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写淘宝买号</view>
				<view class="invite-small-title">填写淘宝买号</view>
				<input type="text" focus="true" class="invite-input" v-model="userInfo.taobaoID"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('TaobaoID')">取消</view>
					<view class="invite-submit" @tap="BindTaobaoID">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- 淘气值 -->
		<uni-popup ref="showTaoqiV" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写淘气值</view>
				<view class="invite-small-title">填写淘气值</view>
				<input type="number" focus="true" class="invite-input" v-model="userInfo.taoqizhi"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('TaoqiV')">取消</view>
					<view class="invite-submit" @tap="BindTaoqiV">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- 信誉等级 -->
		<uni-popup ref="showmLevel" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写信誉等级</view>
				<view class="invite-small-title">填写信誉等级</view>
				<input type="number" focus="true" class="invite-input" v-model="userInfo.mLevel"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('mLevel')">取消</view>
					<view class="invite-submit" @tap="BindmLevel">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- 手机号 -->
		<uni-popup ref="showPhone" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写手机号</view>
				<view class="invite-small-title">填写手机号</view>
				<input type="number" focus="true" class="invite-input" v-model="userInfo.phone" />
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('Phone')">取消</view>
					<view class="invite-submit" @tap="BindPhone">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- QQ -->
		<uni-popup ref="showQQ" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写QQ</view>
				<view class="invite-small-title">填写QQ</view>
				<input type="text" focus="true" class="invite-input" v-model="userInfo.qq"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('QQ')">取消</view>
					<view class="invite-submit" @tap="BindQQ">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- WX -->
		<uni-popup ref="showWX" :type="type2">
			<view class="setInviteID">
				<view class="invite-title">填写WX</view>
				<view class="invite-small-title">填写WX</view>
				<input type="text" focus="true" class="invite-input" v-model="userInfo.weixin"/>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('WX')">取消</view>
					<view class="invite-submit" @tap="BindWX">确定</view>
				</view>
			</view>
		</uni-popup>
		<!-- 常购类目 -->
		<uni-popup ref="showCL" :type="type2">
			<view class="setInviteID CL">
				<view class="invite-title">常购类目</view>
				<view class="clist">
					<view class="cl-type" v-for="(item,index) in allwaysBuy" :key="index"
					@tap="choseType(index)"
					>
						<image :src=" item.is_select ? '../../../static/common/allways-buy-icon.png':'../../../static/common/cl-type-n.png'" class="cl-img"></image>
						<view class="type-text">{{item.type}}</view>
					</view>
				</view>
				<view class="clist" style="border-top: 1px solid rgba(142,142,147,0.13)">
					<view class="cl-type" @tap="otherType">
						<image :src=" other.is_select ? '../../../static/common/allways-buy-icon.png':'../../../static/common/cl-type-n.png'" class="cl-img"></image>
						<view class="type-text">{{other.type}}</view>
					</view>
				</view>
				<view class="invite-btns">
					<view class="invite-cancle" @tap="cancel('CL')">取消</view>
					<view class="invite-submit" @tap="bindBuyType">确定</view>
				</view>
			</view>
		</uni-popup>
		
		<!-- 分享 -->
		<uni-popupShare ref="showshare" :type="type">
			<view class="uni-share">
				<view class="banner">
					<view class="img">
						<canvas  canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}"></canvas>
					</view>
					<view class="tgtit">推广链接：<text class="tugurl">{{qrcoedSrc}}</text></view>
					<view class="sharbuttn">
						<view class="btn" @tap="save">保存二维码</view>
						<view class="btn" @tap="sharurl">复制推广链接</view>
					</view>
					<view class="shartitle"><view>分享</view></view>
					<view class="sharapk">
						<view><image src="../../../static/common/share-wxf.png" @tap="InviteShare('WXSceneSession')"></image></view>
						<view><image src="../../../static/common/share-wxq.png" @tap="InviteShare('WXSenceTimeline')"></image></view>
					</view>
					<view class="bottom">
						<ul>
							<li>1、好友识别二维码通过手机号进行注册</li>
							<li>2、注册完成后您即可得到相应的鼓励金</li>
						</ul>
					</view>
				</view>
			</view>
		</uni-popupShare>
	</view>
	</view>
</template>

<script>
	import commonTitle from'../../../components/titile/title.vue'
	import uniPopup  from'../../../components/uni-popup/uni-popup.vue'
	import { pathToBase64, base64ToPath } from '../../../js_sdk/gsq-image-tools/image-tools/index.js'
	
	import uniPopupShare  from'../../../components/uni-popup/uni-popup.vue'
	import uQRCode from '../../../util/uqrcode.js'
	export default{
		components:{
			commonTitle,
			uniPopup,
			uniPopupShare
		},
		data () {
			return {
				type: 'bottom',
				type2:"center",
				array: [{name:'男'},{name: '女'}],
				index: 0,
				HB: [{hb:'是'},{hb: '否'}],
				mLevel:[
					{leavel:'1颗心',grade:'h1'},{leavel:'2颗心',grade:'h2'},{leavel:'3颗心',grade:'h3'},{leavel:'4颗心',grade:'h4'},{leavel:'5颗心',grade:'h5'},
					{leavel:'1颗钻',grade:'d1'},{leavel:'2颗钻',grade:'d2'},{leavel:'3颗钻',grade:'d3'},{leavel:'4颗钻',grade:'d4'},{leavel:'5颗钻',grade:'d5'},
					{leavel:'皇冠1',grade:'c1'},{leavel:'皇冠2',grade:'c2'},{leavel:'皇冠3',grade:'c3'},{leavel:'皇冠4',grade:'c4'},{leavel:'皇冠5',grade:'c5'},
					{leavel:'超级粉冠1',grade:'pc1'},{leavel:'超级粉冠2',grade:'pc2'},{leavel:'超级粉冠3',grade:'pc3'},{leavel:'超级粉冠4',grade:'pc4'},{leavel:'超级粉冠5',grade:'pc5'},					
					],
				mLevelIndex:0,
				HBIndex: 0,
				apptoken:"",
				userInfo:"",//用户基本信息
				allwaysBuy:"",//常购类目列表
				other:{type:"其他商品",is_select:false},//常购类目-其他商品
				str:"",//页面绑定常购类目标识
				
				qrcoedSrc:"",
				showCanvas:false,
				qrcodeSize:150,
				qrImg:"",
			}
		},
		onLoad() {
			//获取用户信息
			this.apptoken = uni.getStorageSync("apptoken")
			this.getUserInfo();
			this.allwaysBuy = this.$CommonJS.allwaysBuy;//常购类目
			this.getInviteUrl();
		},
		methods: {
			getInviteUrl(){
				//获取邀请链接，邀请链接有时间有效期，所以不能缓存，要实时获取
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.userView,
					data:{
						apptoken:this.apptoken
					},
					success(res) {
							console.log(res)
							if(res.data.success){
								_this.qrcoedSrc = res.data.data.inviteUrl;
								console.log(_this.qrcoedSrc)
							}
					}
				})
			},
			getImgUrl(url){
				//处理头像
				if(url.indexOf('http')==-1){
					return this.$CommonJS.baseurl + url;
				}else{
					return url
				}
			},
			openShare(){
				 this.$refs.showshare.open();
				 this.makeQrcodeImg(this.qrcoedSrc);
			},
			makeQrcodeImg(url){
				console.log(url);
				const _this = this;
				//生成二维码
				uQRCode.make({
					canvasId: 'qrcode',
					text: url,
					size: _this.qrcodeSize,
					margin: 10,
					success: res => {
						console.log(res)
						_this.qrImg = res;
						
					}
				})
			},
			save(){
				uni.saveImageToPhotosAlbum({
						filePath: this.qrImg,
						success: function () {
								uni.showToast({
									title:"图片保存成功"
								})
						}
				});
			},
			sharurl(){
				uni.setClipboardData({
				    data: this.qrcoedSrc,
				    success: function () {
				        uni.showToast({
				        	title:"链接复制成功"
				        })
				    }
				});
			},
			InviteShare(scene){
				uni.share({
				    provider: "weixin",
				    scene: scene,
				    type: 2,
				    imageUrl: this.qrImg,
				    success: function (res) {
				        console.log("success:" + JSON.stringify(res));
				    },
				    fail: function (err) {
				        console.log("fail:" + JSON.stringify(err));
				    }
				});
			},
			choseImg(){
				//打开相册
				let _this = this;
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album','camera'], //从相册选择
				    success: function (res) {
				       // console.log(JSON.stringify(res.tempFilePaths));
								
							//#ifdef APP-PLUS
								uni.getImageInfo({
										src: res.tempFilePaths[0],
										success: function (image) {
												pathToBase64(image.path)
												  .then(base64 => {
														uni.request({
															url:_this.$API.URL + _this.$API.userSetheadimg,
															data:{apptoken:_this.apptoken,headimg:base64},
															method:"POST",
															header:{
																'content-type':'application/x-www-form-urlencoded'
															},
															success(resp) {
																//console.log(resp)
																if(resp.data.success){
																	_this.$CommonJS.showToast("头像上传成功")
																	_this.userInfo.headimg = resp.data.data.headimg;
																}else{
																	_this.$CommonJS.showToast(resp.data.msg);
																}
															}
														})
												  })
												  .catch(error => {
												    console.error(error)
												  })
										}
								});
							//#endif
							//#ifdef MP-WEIXIN
							/*uni.getFileSystemManager().readFile({
							    filePath: res.tempFilePaths[0], //选择图片返回的相对路径
							    encoding: 'base64', //编码格式
							    success: res => { //成功的回调
							        let base64 = 'data:image/jpeg;base64,' + res.data //不加上这串字符，在页面无法显示的哦
							       _this.setingHeadImg(base64);
							    }
							})*/
							//#endif
				    }
				});
			},
			setingHeadImg(url){
				uni.request({
					url:_this.$API.URL + _this.$API.userSetheadimg,
					data:{apptoken:_this.apptoken,headimg:url},
					success(resp) {
						//console.log(resp)
					}
				})
			},
			getUserInfo(){
				//用户信息加载
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.user_view,
					data:{apptoken:this.apptoken},
					success(res) {
						console.log(res)
						if(res.data.success){
							_this.userInfo = res.data.data;
						}
						
					}
				})
			},
			setAddress(){
				//收货地址
				const _this = this;
				
				const userAddress = {
					sarea:this.userInfo.sarea,
					scity:this.userInfo.scity,
					sprovince:this.userInfo.sprovince,
					address:this.userInfo.address,
					receiver:this.userInfo.receiver,
					receiverPhone:this.userInfo.receiverPhone
				}
				if(!uni.getStorageSync("userAddress")){
					uni.setStorage({
						key:"userAddress",
						data:userAddress,
						success() {
							_this.$CommonJS.navigateTo("../sub-address/sub-address")
						}
					})
				}else{
					this.$CommonJS.navigateTo("../sub-address/sub-address");
				}
				
			},
			bindPickerChange: function(e) {
				//绑定性别
				const _this = this;
				//console.log(this.userInfo.sex)
				if(!this.userInfo.sex){
					//初次绑定
					if(e.detail.value == 0){
						this.userInfo.sex = "男";
					}else if(e.detail.value == 1){
						this.userInfo.sex = "女";
					}
					uni.request({
						url:this.$API.URL + this.$API.updateSex,
						data:{apptoken:this.apptoken,sex:this.userInfo.sex},
						success(res) {
							console.log(res);
							if(res.data.success){
								//提交成功同步更新页面数据
								_this.index = e.detail.value;
							}else{
								_this.$CommonJS.showToast(res.data.msg)
							}
						}
					})
				}
			},
			bindPickerChangeHB: function(e) {
				
				//绑定花呗
				const _this = this;
				if(!this.userInfo.isHuabei){
					//初次绑定
					if(e.detail.value == 0){
						this.userInfo.isHuabei = 1;
					}else if(e.detail.value == 1){
						this.userInfo.isHuabei = 0;
					}
					uni.request({
						url:this.$API.URL + this.$API.updateHuabei,
						data:{apptoken:this.apptoken,isHuabei:this.userInfo.isHuabei},
						success(res) {
							console.log(res);
							if(res.data.success){
								//提交成功同步更新页面数据
								_this.HBIndex = e.detail.value;
							}else{
								_this.$CommonJS.showToast(res.data.msg)
							}
						}
					})
				}
			},
			bindPickerChangeLevel(e){
				//绑定信用等级
				const _this = this;
				console.log(e)
				if(!this.userInfo.mLevel){
					//初次绑定
				
					switch(e.detail.value){
						case 0:
							this.userInfo.mLevel = "1颗心";
							break;
						case 1:
							this.userInfo.mLevel = "2颗心";
							break;
						case 2:
							this.userInfo.mLevel = "3颗心";
							break;
						case 3:
							this.userInfo.mLevel = "4颗心";
							break;
						case 4:
							this.userInfo.mLevel = "5颗心";
							break;
						case 5:
							this.userInfo.mLevel = "1颗钻";
							break;
						case 6:
							this.userInfo.mLevel = "2颗钻";
							break;
						case 7:
							this.userInfo.mLevel = "3颗钻";
							break;
						case 8:
							this.userInfo.mLevel = "4颗钻";
							break;
						case 9:
							this.userInfo.mLevel = "5颗钻";
							break;
						case 10:
							this.userInfo.mLevel = "皇冠1";
							break;
						case 11:
							this.userInfo.mLevel = "皇冠2";
							break;
						case 12:
							this.userInfo.mLevel = "皇冠3";
							break;
						case 13:
							this.userInfo.mLevel = "皇冠4";
							break;
						case 14:
							this.userInfo.mLevel = "皇冠5";
							break;
						case 15:
							this.userInfo.mLevel = "超级粉冠1";
							break;
						case 16:
							this.userInfo.mLevel = "超级粉冠2";
							break;
						case 17:
							this.userInfo.mLevel = "超级粉冠3";
							break;
						case 18:
							this.userInfo.mLevel = "超级粉冠4";
							break;
						case 19:
							this.userInfo.mLevel = "超级粉冠5";
							break;
					}
					
					
					
					
					uni.request({
						url:this.$API.URL + this.$API.updateMLevel,
						data:{apptoken:this.apptoken,mLevel:this.userInfo.mLevel},
						success(res) {
							console.log(res);
							if(res.data.success){
								//提交成功同步更新页面数据
								_this.mLevelIndex = e.detail.value;
							}else{
								_this.$CommonJS.showToast(res.data.msg)
							}
						}
					})
				}
			},
			openInviteIDQcode(){
				this.$refs.showInviteID.open()
			},
			openEdit(){
				 this.$refs.showshare.open()
			},
			openAge(){
				//绑定年龄
				if(!this.userInfo.age){
					this.$refs.showAge.open()
				}else{
					return;
				}
			},
			BindAge(){
				//修改年龄提交
				const _this = this;
				if(this.userInfo.age){
					const url = this.$API.URL + this.$API.updateAge;
					const data = {apptoken:this.apptoken,age:this.userInfo.age};
					this.UPdata(url,data,'Age');
				}else{
					this.$CommonJS.showToast("请填写年龄")
				}
			},
			openTaobaoID(){
				//绑定淘宝ID
				if(!this.userInfo.taobaoID){
					this.$refs.showTaobaoID.open();
				}
			},
			BindTaobaoID(){
				//提交淘宝号
				if(this.userInfo.taobaoID){
					const url = this.$API.URL + this.$API.updateTaobaoID;
					const data = {apptoken:this.apptoken,taobaoID:this.userInfo.taobaoID};
					this.UPdata(url,data,'TaobaoID');
				}else{
					this.$CommonJS.showToast("请填写淘宝ID")
				}
				
			},
			openTaoqiV(){
				//打开淘气值输入框
				if(!this.userInfo.taoqizhi){
					this.$refs.showTaoqiV.open();
				}
			},
			BindTaoqiV(){
				//提交淘气值
				if(!this.userInfo.taoqizhi){
					this.$CommonJS.showToast("请填写淘气值");
				}else{
					const url = this.$API.URL + this.$API.updateTaoqizhi;
					const data = {apptoken:this.apptoken,taoqizhi:this.userInfo.taoqizhi};
					this.UPdata(url,data,'TaoqiV');
				}
			},
			openmLevel(){
				//打开信用等级输入框
				if(!this.userInfo.mLevel){
					this.$refs.showmLevel.open();
				}
			},
			BindmLevel(){
				//提交信用等级
				if(!this.userInfo.mLevel){
					this.$CommonJS.showToast("请填写信誉值");
				}else{
					const url = this.$API.URL + this.$API.updateMLevel;
					const data = {apptoken:this.apptoken,mLevel:this.userInfo.mLevel};
					this.UPdata(url,data,'mLevel');
				}
			},
			openPhone(){
				 this.$refs.showPhone.open()
			},
			BindPhone(){
				//提交手机号
				if(!this.userInfo.phone){
					this.$CommonJS.showToast("请填写手机号");
				}else{
					if(!(/^1[3456789]\d{9}$/.test(this.userInfo.phone))){
						this.$CommonJS.showToast("手机号格式不正确");
						return;
					}
					const url = this.$API.URL + this.$API.userPhone;
					const data = {apptoken:this.apptoken,phone:this.userInfo.phone};
					this.UPdata(url,data,'Phone');
				}
			},
			BindQQ(){
				//绑定qq提交
				if(!this.userInfo.qq){
					this.$CommonJS.showToast("请填写QQ号");
				}else{
					const url = this.$API.URL + this.$API.account_qq;
					const data = {apptoken:this.apptoken,qq:this.userInfo.qq};
					this.UPdata(url,data,'QQ');
				}
			},
			BindWX(){
				//绑定微信提交
				if(!this.userInfo.weixin){
					this.$CommonJS.showToast("请填写微信号");
				}else{
					const url = this.$API.URL + this.$API.userWeixin;
					const data = {apptoken:this.apptoken,weixin:this.userInfo.weixin};
					this.UPdata(url,data,'WX');
				}
			},
			UPdata(url,data,name){
				const _this = this;
				uni.request({
					url:url,
					data:data,
					success(res) {
						console.log(res);
						if(!res.data.success){
							_this.$CommonJS.showToast(res.data.msg)
						}else{
							_this.cancel(name);
							if(url.indexOf('updateTaobaoID')!=-1){
								uni.setStorage({
									key:"taobaoID",
									data:data.taobaoID,
								})
							}
						}
					}
				})
			},
			
			openQQ(){
				 this.$refs.showQQ.open()
			},
			openWX(){
				 this.$refs.showWX.open()
			},
			showCL(){
				//常购类目
				if(!this.userInfo.type){
					this.$refs.showCL.open()
				}
			},
			choseType(index){
				//常购类目
				//1.判断已选类目个数，最多选3个类目
				const selectNum = this.allwaysBuy.filter(item=>{
					return item.is_select;
				})
				if(selectNum.length >= 3 && !this.allwaysBuy[index].is_select){
					this.$CommonJS.showToast("最多选3个类目");
					return;
				}else{
					this.allwaysBuy[index].is_select = !this.allwaysBuy[index].is_select;
				}
				this.other.is_select = false;
			},
			otherType(){
				//常购类目其他商品
				this.other.is_select = !this.other.is_select;
				this.allwaysBuy.forEach(item=>{
					 item.is_select = false;
				})
			},
			bindBuyType(){
				//提交常购类目
				const _this = this;
				var str = "";
				const buy_type = this.allwaysBuy.filter(item=>{
					return item.is_select;
				})
				
				
				if(buy_type.length < 1 && !this.other.is_select){
					this.$CommonJS.showToast('请先选择类目');
				}else{
					if(this.other.is_select){
						str = "其他商品";
					}else{
						const typeString = [];
						 buy_type.forEach(item=>{
							typeString.push(item.type);
						})
					  str = typeString.join(',');
						//console.log(str)
					}
					//console.log(str)
					uni.request({
						url:this.$API.URL + this.$API.updateType,
						data:{apptoken:this.apptoken,type:str},
						success(res) {
							//console.log(res)
							if(res.data.success){
								_this.userInfo.type = str;
								_this.cancel('CL')
							}else{
								_this.$CommonJS.showToast(res.data.msg)
							}
						}
					})
				}
			},
			cancel(type) {
				this.$refs['show' + type].close()
			},
			
		}
		
	}
</script>

<style>
	@import url("sub-userInfo.css");
	.tugurl{
		color: #999;
	}
	.sharbuttn{
		display: flex;
		justify-content: center;
	}
	.shartitle{
		    width: 80%;
			text-align: center;
			margin-left: 10%;
			border-bottom: 1px solid #dddddd;
			position: relative;
			height: 60upx;
	}
	.tgtit{
		text-align: center;
		font-size: 11px;
		margin-top: 20upx;
	}
	.shartitle view{
		    height: 50upx;
			line-height: 50upx;
			font-size: 28upx;
			color: #999;
			width: 120upx;
			margin: 32upx auto;
			position: absolute;
			background: #fff;
			left: 50%;
			margin-left: -60upx;
	}
	.sharapk{
	 display: flex;
	 justify-content: center;
	 margin: 20upx auto;
	}
	.sharapk view{
		margin: 20upx 50upx;
	}
	.sharapk view image{
		height: 80upx;
		width: 80upx;
	}
	.banner{
		width: 100% ;
		background-color: #FFFFFF;
		border-radius: 60upx 60upx 0 0;
		margin-top: -60upx;
	}
	.banner dl{
		margin-top: -80upx;
	}
	.banner dl dt{
		text-align: center;
	}
	.banner dl dt image{
		width: 160upx;
		height: 160upx;
		border-radius:50% ;
	}
	.banner dl dd{
		text-align: center;
	}
	.img{
		width: auto;
		height: auto;
		margin: 0 auto;
		margin-top: 60upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding-top: 60upx;
	}
	
	.btn{
		width: 260upx;
		height: 60upx;
		line-height: 60upx;
		margin: 0 auto;
		margin-top: 60upx;
		border-radius: 40upx;
		border: 0;
		font-size: 26upx;
		outline: 0;
		background: #33b17b;
		color: #FFFFFF;
		text-align: center;
	}
	.bottom{
		width: 100%;
		height: auto;
		background-size: 20%;
		padding-bottom: 50upx;
	}
	.bottom ul{
		padding-left: 40upx;
		box-sizing: border-box;
	}
	.bottom ul li{
		width: 100%;
		height: 40upx;
		font-size: 13px;
		list-style: none;
	}
</style>
